// 시세 데이터 카운터
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>

#include <hiredis/hiredis.h>
#include <stdint.h>
#include <amqp.h>
#include <amqp_framing.h>

#define BUFSIZE 1024

int main(int argc, char const *argv[])
{
	FILE *f = fopen("data.log", "r");
	char msg[1024];
	char counts[10000][20];
	int count[10000];
	int i;

	for(i=0; i<10000; i++)
	{
		memset(counts[i], 0, sizeof(counts[i]));
		count[i]=0;
	}

	while(fgets(msg, 1024, f)!=NULL)
	{
		if(strncmp(msg,"A3011", 5)==0 || strncmp(msg, "B6011", 5)==0)
		{
			char* code_num = (char*)substring(msg, 5, 16);
			for(i=0; i<10000; i++)
			{
				if(strlen(counts[i])==0) strcpy(counts[i], code_num);
				if(strncmp(counts[i],code_num,12)==0)
				{
					count[i]++;
					break;
				}
			}
			free(code_num);
		}
	}

	for(i=0; i<10000; i++)
	{
		if(count[i]>500)
			printf("%s - %d\n", counts[i], count[i]);
		if(strlen(counts[i])==0) break;
	}
	return 0;
}